/**
 * CC2003
 * 
 * For the course CC2003 - Algorithms and Data Structures of UVG (Universidad del Valle de Guatemala, http://uvg.edu.gt)
 * 
 * 
 * 
 * SVN Repository of my course projects: http://cc2003.svn.sourceforge.net/viewvc/cc2003/
 * 
 * 
 * Copyright (C) 2009 Carlos Lopez Camey
 * visit me at http://kmels.net or write me at c.lopez@kmels.net
 * 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package main;

import java.util.ArrayList;

/**
 * @author kmels
 *
 */
public class RegistroFisico<E> {

	String nombreDelCampoIndexando;
	ArrayList<String> listadeValores;
	ArrayList<String> listadeNombres;
	ArrayList<String> listadeTipos;
	int cantidadDecamposMetidos;
	
	public RegistroFisico(String nombreDelCampoQueEstaIndexando){
	
		this.cantidadDecamposMetidos =0 ;
		this.nombreDelCampoIndexando = nombreDelCampoQueEstaIndexando;
		this.listadeValores = new ArrayList<String>();
		this.listadeNombres = new ArrayList<String>();
		this.listadeTipos = new ArrayList<String>();
	}
	
	public void agregarValor(String nombreDelCampo, String valor, String tipoDeValor) throws RegistroYaTieneCampoIndexado{
		
		boolean esElPrimerValor =false;
		
		if(nombreDelCampoIndexando.equals(nombreDelCampo))
			esElPrimerValor = true;
		
		if(esElPrimerValor){
			/*if (this.nombreDelCampoIndexando==null)
				this.nombreDelCampoIndexando = nombreDelCampo;
			else
				//nombre del campo indexado ya fue establecido, entonces hay error
				throw new RegistroYaTieneCampoIndexado();*/
			
			listadeValores.add(0, valor);
			listadeNombres.add(0,nombreDelCampo);
			listadeTipos.add(0,tipoDeValor);
		} else{
			listadeValores.add(valor);
			listadeNombres.add(nombreDelCampo);
			listadeTipos.add(tipoDeValor);
		}
		this.cantidadDecamposMetidos++;
	}
	
	public ArrayList<String> getValores(){
		return this.listadeValores;
	}
	
	public ArrayList<String> getNombres(){
		return this.listadeNombres;
	}
	
	public ArrayList<String> getTipos(){
		return this.listadeTipos;
	}
	
	public String toString(){
		String muestra="Campo Indexado: " + nombreDelCampoIndexando + "\nValores: ";
		for(int i=0; i<listadeValores.size();i++)
			muestra+=listadeValores.get(i);
		
		return muestra;
	}
}